package com.gzdh.dishrecognition.ui.adapter.report;

import android.content.Context;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.gzdh.dishrecognition.R;
import com.gzdh.dishrecognition.config.SysConstConfig;
import com.gzdh.dishrecognition.model.LcReportDto;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class ScanTakeAdapter extends RecyclerView.Adapter<ScanTakeAdapter.ViewHolder> {

    private Context mContext;
    private List<LcReportDto> lcReportDtoList;

    private String dinner;

    private int fontSize;

    private int paddingSize;

    public List<LcReportDto> getLcReportDtoList() {
        return lcReportDtoList;
    }

    public void setLcReportDtoList(List<LcReportDto> lcReportDtoList) {
        this.lcReportDtoList = lcReportDtoList;
        notifyDataSetChanged();
    }

    public void setDinner(String dinner) {
        this.dinner = dinner;
        notifyDataSetChanged();
    }

    public List<Long> getPkIdList() {
        List<Long> list = new LinkedList<>();
        for (LcReportDto lcReportDto : this.lcReportDtoList) {
            list.add(lcReportDto.getPkId());
        }
        return list;
    }

    public ScanTakeAdapter(Context context) {
        mContext = context;
        this.lcReportDtoList = new ArrayList<>();
        dinner = "";
        this.fontSize = SysConstConfig.getInstance().getScanTakeFontSize();
        this.paddingSize = -1;
    }

    public ScanTakeAdapter(Context context, int fontSize, int tbPaddingSize) {
        mContext = context;
        this.lcReportDtoList = new ArrayList<>();
        dinner = "";
        this.fontSize = fontSize;
        this.paddingSize = tbPaddingSize;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_scan_take, parent, false);
        return new ViewHolder(itemView, fontSize, paddingSize);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.indexTv.setText(String.valueOf(position + 1));
        holder.dinnerTv.setText(dinner);
        holder.orderTv.setText(lcReportDtoList.get(position).getZFSerialNumber());
        holder.hNameTv.setText(String.valueOf(lcReportDtoList.get(position).gethName()).trim());
        holder.slTv.setText(lcReportDtoList.get(position).getSl());
    }

    @Override
    public int getItemCount() {
        return lcReportDtoList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mainLinear;

        TextView indexTv;
        TextView dinnerTv;
        TextView orderTv;
        TextView hNameTv;
        TextView slTv;

        ViewHolder(View item, int size, int paddingSize) {
            super(item);
            mainLinear = item.findViewById(R.id.mainLinear);
            if(paddingSize != -1) {
                mainLinear.setPadding(0, paddingSize, 0, paddingSize);
            }

            indexTv = item.findViewById(R.id.indexTv);
            indexTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);

            dinnerTv = item.findViewById(R.id.dinnerTv);
            dinnerTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);

            orderTv = item.findViewById(R.id.orderTv);
            orderTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);

            hNameTv = item.findViewById(R.id.hNameTv);
            hNameTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);

            slTv = item.findViewById(R.id.slTv);
            slTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
        }
    }

}
